\defmodule{SquareMathFunction}

Represents a function computing
$(af(x) + b)^2$ for a user-defined function
$f(x)$.

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        SquareMathFunction
 * Description:  function computing the square of another function
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       Éric Buist
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.functions;\begin{hide}

\end{hide}

public class SquareMathFunction implements MathFunctionWithFirstDerivative \begin{hide} {
   private MathFunction func;
   private double a, b;
\end{hide}

   public SquareMathFunction (MathFunction func)\begin{hide} {
      this (func, 1, 0);
   }\end{hide}
\end{code}
\begin{tabb}   Constructs a new square function
 for function \texttt{func}.
 The values of the constants are
 $a=1$ and $b=0$.
\end{tabb}
\begin{htmlonly}
   \param{func}{the function $f(x)$.}
\end{htmlonly}
\begin{code}

   public SquareMathFunction (MathFunction func, double a, double b)\begin{hide} {
      if (func == null)
         throw new NullPointerException();
      this.func = func;
      this.a = a;
      this.b = b;
   }\end{hide}
\end{code}
\begin{tabb}   Constructs a new power function
 for function \texttt{func}, and constants
 \texttt{a} and \texttt{b}.
\end{tabb}
\begin{htmlonly}
   \param{func}{the function $f(x)$.}
   \param{a}{the multiplicative constant.
   \param{b}{the additive constant.}
\end{htmlonly}
\begin{code}

   public MathFunction getFunction()\begin{hide} {
      return func;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the function $f(x)$.
\end{tabb}
\begin{htmlonly}
   \return{the function.}
\end{htmlonly}
\begin{code}

   public double getA()\begin{hide} {
      return a;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the value of $a$.
\end{tabb}
\begin{htmlonly}
   \return{the value of $a$.}
\end{htmlonly}
\begin{code}

   public double getB()\begin{hide} {
      return b;
   }\end{hide}
\end{code}
\begin{tabb}   Returns the value of $b$.
\end{tabb}
\begin{htmlonly}
   \return{the value of $b$.}
\end{htmlonly}
\begin{code}\begin{hide}

   public double evaluate (double x) {
      final double v = a*func.evaluate (x) + b;
      return v*v;
   }

   public double derivative (double x) {
      final double fder = MathFunctionUtil.derivative (func, x);
      return 2*a*(a*func.evaluate (x) + b)*fder;
   }
}\end{hide}
\end{code}
